package utils

import (
	"fmt"
	"io"
	"crypto/md5"
	"net"
)


/**
加密工具方法,进行MD5加密
 */
func GetMD5(data string) string {
	h := md5.New();
	io.WriteString(h, data);
	return fmt.Sprintf("%x", h.Sum(nil));

}

func GetMD5ByByte(prefix, suffix  []byte, separator byte) string {
	var data []byte
	data = append(prefix, separator)
	data = append(data, suffix...)

	h := md5.New();
	h.Write(data)
	return fmt.Sprintf("%x", h.Sum(nil));

}

func md5Data()  {
	
}



func GetIP() (ip string, err error) {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return
	}

	for _, address := range addrs {

		// 检查ip地址判断是否回环地址
		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				return ipnet.IP.String(), nil
			}
		}
	}

	return
}